import { BillboardGraphics, CallbackPositionProperty, Cartesian3,  Entity, HeightReference, HorizontalOrigin,  VerticalOrigin, Viewer } from "cesium";
import { BaseDraw, GeometryType } from "../BaseDraw";
import EventDispatcher from "@/system/EventDispatcher/EventDispatcher";

export default class CommonBillboard extends BaseDraw {
    private billboardOption:BillboardGraphics.ConstructorOptions

    constructor(viewer: Viewer, dispatcher: EventDispatcher) {
        super(viewer, dispatcher);
        this.geometryType = GeometryType.COMMON_LABEL;
        this.billboardOption={
            // 图像地址，URI或Canvas的属性
                image: '/testdata/images/mark1.png',
                // 高度（以像素为单位）
                height: 50,
                // 宽度（以像素为单位）
                width: 50,               
                // 相对于坐标的垂直位置
                verticalOrigin: VerticalOrigin.BOTTOM,
                // 相对于坐标的水平位置
                horizontalOrigin: HorizontalOrigin.CENTER,                
                // 关闭深度测试，避免被地形遮挡
                disableDepthTestDistance: Number.POSITIVE_INFINITY,
                // 贴地显示（与 point 保持一致）
                heightReference: HeightReference.CLAMP_TO_GROUND,
                // 应用于图像的统一比例。比例大于会1.0放大标签，而比例小于会1.0缩小标签。
                scale: 1.0,
                // 是否显示
                show: true

        }
    }

    protected buildFinalEntity(): Entity {
        const pos = this.getPositions()[0];
        return this.viewer.entities.add({
            position: pos,
            // point: { pixelSize: 12, color: Color.RED, heightReference: HeightReference.CLAMP_TO_GROUND, disableDepthTestDistance: Number.POSITIVE_INFINITY },
            billboard: this.billboardOption

        });
    }

    protected buildTempEntity(): Entity | undefined {
        return this.viewer.entities.add({
            position: new CallbackPositionProperty(() => this.tempCursor || new Cartesian3(), false),
            billboard: this.billboardOption
        });
    }

    protected onLeftClick(e: any) {
        super.onLeftClick(e);
        // 点只需要 1 次点击即可结束
        this.finish();
    }

}